#include "stdafx.h"
#include "speaker.h"
#include "iltsoundmgr.h"
#include "clientinterfaces.h"
#include <string>



speaker::speaker()
{
	init();
		
}
speaker::speaker( const char* filename )
{
	init();
	SAFE_STRCPY(m_sound_info.m_szSoundName,filename);
}


void speaker::play_sound()
{
	if (GetTickCount()-m_ticks>m_update_ticks)
	{
		g_pLTCSoundMgr->PlaySound(&m_sound_info,m_sound_handle);
		m_ticks=GetTickCount();
	}


	
	

	
	
}

void speaker::init()
{
	m_sound_handle=0;
	memset(&m_sound_info,0,sizeof(m_sound_info));
	m_sound_info.m_dwFlags|=PLAYSOUND_CLIENT;
	m_sound_info.m_dwFlags|=PLAYSOUND_CTRL_VOL; 
	//m_sound_info.m_dwFlags|=PLAYSOUND_LOOP; 
	m_sound_info.m_nVolume=50;
	m_sound_info.m_fInnerRadius=10;
	m_sound_info.m_fOuterRadius=100;
	m_update_ticks=500;
}

void speaker::set_type( SOUND_TYPE _type )
{
	switch(_type)
	{
	case SOUND_TYPE_3D:
		m_sound_info.m_dwFlags|=PLAYSOUND_3D;
		//m_sound_info.m_dwFlags&=~PLAYSOUND_CTRL_VOL;
		//m_sound_info.m_dwFlags&=~PLAYSOUND_GETHANDLE; 
		break;
	case SOUND_TYPE_AMBIENT:
		m_sound_info.m_dwFlags|=PLAYSOUND_AMBIENT;
		break;
	case SOUND_TYPE_LOCAL:
		m_sound_info.m_dwFlags|=PLAYSOUND_LOCAL;
		break;
	}


}

bool speaker::is_done()
{
	bool temp_done;
	g_pLTCSoundMgr->IsSoundDone(m_sound_handle,temp_done);
	return temp_done;
}

void speaker::close_sound()
{
	if (m_sound_handle)
	{
		g_pLTCSoundMgr->KillSound(m_sound_handle);
		m_sound_handle=0;
	}
}

void speaker::update_volume()
{
	g_pLTCSoundMgr->UpdateVolumeSettings();

}